/*-+-*****************************************************************************
 Copyright (C) 2009-2012 Oceanside Software Corporation (R)
 Dallas, Texas

 Author       : Jason T. Brower
 Purpose      : This file is part of a point-of-sale software package
                originally written for Table-Service Restaurants.
              
 Date         : July 8th of 2012
              
 History      : The application that this software file belongs to was 
                written over a 3-Year period.  The first version was written
                in C# .Net 3.5 using Windows Forms.  Being new to .Net at
                the time, I soon learned of Windows Presentation Foundation,
                liked the graphics capabilities and databinding so I
                migrated to WPF.  When the .Net 4.0 framework was released
                the application was migrated from 3.5 to 4.0. Now today,
                .Net 4.5 RC is out and I was already in process of migrating
                before I made this public.
                
Excuse Me     : Please excuse the coding style, it is not representative of
                my typical work.  During the three years I was under a very
                tight budget, constantly running out of funding and was 
                working 18 hour days hyped up on 5-Hour Energy.  The 
                design is not textbook.  It is monolythic because of
                previous issues I will not get into.  There are few comments
                in the code and the ones that are there may be incorrect.
                
What it is not: This is not the exact version that I took through PA-DSS 2.0
                nor is it the exact version running at my customer sites.
                I removed some details for security purposes including some
                encryption algorithms.  The reporting was removed because
                I was including a third party library that cannot be 
                published with this Open Source.
                
What it is    : This application has been running at high volume restaraunts
                for over a year.  It never freezes, crashes or does anything
                unexpected.  So long as it is built, installed and configured
                correctly, it is a strong system that we can all enhance.

Contact       : Please note that I can no longer work for free.  However, you
                can reach me at information@oceansidesw.com.                                                      

*********************************************************************************/
using System;
using System.Data.Objects;
using System.Linq;
using System.Collections.Generic;

#if _LOCALDB
  using Oceanside.LocalDB;
#else
using Oceanside.RemoteDB;
#endif

#if _LOCALDB
  namespace Oceanside.LocalDB
#else
namespace Oceanside.RemoteDB
#endif
{
    /// <summary>
    /// A group of products that a like in nature.
    /// </summary>
    public partial class PRODUCT_GROUP
    {
        #region Additional Properties
        /// <summary>
        /// 
        /// </summary>
        private int myProductGroupListIndex = -1;
        public int MyProductGroupListIndex
        {
            get { return myProductGroupListIndex; }
            set { myProductGroupListIndex = value; }
        }

        /// <summary>
        /// 
        /// </summary>
        private int myExceptionModGroupListIndex = -1;
        public int MyExceptionModGroupListIndex
        {
            get { return myExceptionModGroupListIndex; }
            set { myExceptionModGroupListIndex = value; }
        }
        #endregion Additional Properties

        /// <summary>
        /// 
        /// </summary>
        /// <param name="objectContext"></param>
        /// <param name="isLocal"></param>
        public void Add(DominicaEntities objectContext)
        {
            objectContext.PRODUCT_GROUPS.AddObject(this);
        }

        public static string PopupSelectProductGroup(out Int64 chosenDbId)
        {
            chosenDbId = DominicaEntities.CONST_ALL_DB_OBJECTS_WILDCARD;
            try
            {
                List<String> stringsList = new List<string>();
                List<Int64> pidsList = new List<Int64>();

                using (DominicaEntities context = new DominicaEntities(DominicaEntities.GetEfConString()))
                {
                    var q = from PRODUCT_GROUP in context.PRODUCT_GROUPS where PRODUCT_GROUP.IsDeleted == false select PRODUCT_GROUP;

                    if (q.Any())
                    {
                        stringsList.Add("All Groups");
                        pidsList.Add(DominicaEntities.CONST_ALL_DB_OBJECTS_WILDCARD);
                        foreach (PRODUCT_GROUP pg in q)
                        {
                            stringsList.Add(pg.Name);
                            pidsList.Add(pg.Id);
                        }
                    }
                }

                BoundObjectStringSelectionListBox dialog = new BoundObjectStringSelectionListBox(stringsList, pidsList);
                dialog.SetMessage("Select a Main Product Category and the System will Print all Product Sales for the Main Product Category you have selected.");
                dialog.ShowDialog();

                if (BoundObjectStringSelectionListBox.LastResponse == UserResponse.ENTER)
                {
                    chosenDbId = BoundObjectStringSelectionListBox.ChosenDbId;
                    return BoundObjectStringSelectionListBox.ChosenString;
                }
                else
                {
                    return null;
                }
            }
            catch (Exception exc)
            {
                Constants.ErrorDispatcher.Notify(Error.EType.E_REPORT_ERROR, exc);
            }
            return null;
        }
        public static PRODUCT_GROUP GetProductGroupById(Int64 id, DominicaEntities objectContext)
        {
            PRODUCT_GROUP p = null;
            p = objectContext.PRODUCT_GROUPS.Where(r => r.Id == id).FirstOrDefault();
            return p;
        }

        public PRICE_INTERVAL_DISCOUNT GetCurrentPriceIntervalDiscount()
        {
            PRICE_INTERVAL_DISCOUNT discount = null;
            if (this.PRICE_INTERVAL_DISCOUNTS.Count > 0)
            {
                DateTime now = DateTime.Now;
                foreach (PRICE_INTERVAL_DISCOUNT pid in PRICE_INTERVAL_DISCOUNTS)
                {
                    if (Functions.IsInBetweenTimeFrame(now, pid.StartTime, pid.EndTime))
                    {
                        discount = pid;
                        break;
                    }
                }
            }
            return discount;
        }
    }
}
